<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-9-19
 * Time: 上午9:41
 */
print_r($_REQUEST);
print_r($_POST);
print_r($_GET);

$appkey  = '23232967';//正式
$appsecret = '13ef824b903fae7e56a9b78055e38f82';//正式
$url = 'https://oauth.taobao.com/token';
if (isset($_GET['code'])) {
    $postfields= array(
        'grant_type'=>'authorization_code',
        'client_id'=> $appkey,
        'client_secret'=>$appsecret,
        'code'=>$_GET['code'],
        'redirect_uri'=>'http://www.12301.cc/module/taobao/auth.php');
    $post_data = '';
    foreach($postfields as $key=>$value){
        $post_data .="$key=".urlencode($value)."&";}
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
//指定post数据
    curl_setopt($ch, CURLOPT_POST, true);
//添加变量
    curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_data,0,-1));
    $output = curl_exec($ch);
    $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    echo $httpStatusCode;
    curl_close($ch);
    var_dump($output);
}

//Array ( [code] => HVnAWLDbNKDdJpo5PYU4And9183078 [state] => ) Array ( ) Array ( [code] => HVnAWLDbNKDdJpo5PYU4And9183078 [state] => )
?>
